// don't half to include usal stuff because included in gamemanager.h

#include "gamemanager.h"
#include <iostream>

using namespace std;

GameManager::GameManager()
{
    cout<< "game manager created!\n";
}

void GameManager::run()
{
    video::E_DRIVER_TYPE driverType;

	printf("Please select the driver you want for this example:\n"\
		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
		" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
		" (f) NullDevice\n (otherKey) exit\n\n");

	char i;
	std::cin >> i;

	switch(i)
	{
		case 'a': driverType = video::EDT_DIRECT3D9;break;
		case 'b': driverType = video::EDT_DIRECT3D8;break;
		case 'c': driverType = video::EDT_OPENGL;   break;
		case 'd': driverType = video::EDT_SOFTWARE; break;
		case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
		case 'f': driverType = video::EDT_NULL;     break;

	}

	// create device and exit if creation failed

	IrrlichtDevice* device =
		createDevice(driverType, core::dimension2d<s32>(640, 480));

	if (device == 0)
		cout<< "game creation faild!!!!\n"; // could not create selected driver.

	device->setWindowCaption(L"Load .irr file example");

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
        gui::IGUIEnvironment* env = device->getGUIEnvironment();
        io::IFileSystem* filesys = device->getFileSystem();

	cout<< "finished init.";

    cout<< "starting game";
    CollisionMaker mk(device), *CMngr;
    CMngr = &mk;
    GUIManager GUIMngr;
    cout<< "make collisnmaker obj";
    PlayerManager player(CMngr);
    cout<< "made player\n";    mk.LoadScene("scenes/Scene.irr");
    cout<< "here at load";
	/*
	That was it already. Now add a camera and draw the scene
	*/

    GUIMngr.UpdateGUI(device, "score", "0"); //Irrlicht device, what to change (score), what to change it too (0)
    mk.AddCollisionCam ();

cout<< "collision cam added";

	// and draw everything.

	int lastFPS = -1;

	while(device->run()) {
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, video::SColor(0,200,200,200));
		smgr->drawAll();
                env->drawAll();
		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
		  core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
		  str += driver->getName();
		  str += "] FPS:";
		  str += fps;

		  device->setWindowCaption(str.c_str());
		  lastFPS = fps;
		}

	}
	}
	device->drop();

}
